package com.lancoo.znbkxx.teacher.diagnosis

import android.annotation.SuppressLint
import android.graphics.Color
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.model.data.Vocab
import com.lancoo.znbkxx.teacher.utils.HtmlUtils
import kotlinx.android.synthetic.main.item_master_words.view.*
import java.math.BigDecimal

/**
 * @author : Admin
 * @date   : 2020/12/21
 * @desc   :
 */
class StuVocabInfoListAdapter(data: List<Vocab>) : BaseQuickAdapter<Vocab, BaseViewHolder>(data) {
    init {
        mLayoutResId = R.layout.item_master_words
    }

    @SuppressLint("SetTextI18n")
    override fun convert(helper: BaseViewHolder, item: Vocab?) {
        with(helper.itemView) {
            val span = SpannableStringBuilder("${item!!.ZsdString}(${item.ApplicationRequire})")
            val spanColor = ForegroundColorSpan(Color.parseColor(when (item.ApplicationRequire) {
                "常考" -> "#00afff"
                "次常考" -> "#00c0a2"
                else -> "#999999"
            }))
            val spanSize = AbsoluteSizeSpan(10, true)
            span.setSpan(spanColor, span.lastIndexOf("("), span.length,
                    SpannableString.SPAN_EXCLUSIVE_INCLUSIVE)
            span.setSpan(spanSize, span.lastIndexOf("("), span.length,
                    SpannableString.SPAN_EXCLUSIVE_INCLUSIVE)
            tv_words.text = span
            tv_test_rate.text = HtmlUtils.setText(
                    "测试概率:<font color='#00c0a2'>${BigDecimal(item.TestRate).setScale(2,
                            BigDecimal.ROUND_HALF_UP)}</font>")
            tv_point.text = HtmlUtils.setText(
                    "达标分:<font color='#ff9900'>${item.StandardScore}</font>")
            tv_excellent_point.text = HtmlUtils.setText(
                    "优秀学生认知积分:<font color='#00afff'>${BigDecimal(item.ExcellentScore).setScale(1,
                            BigDecimal.ROUND_HALF_UP).toPlainString()}分</font>")
            tv_personal_score.text = BigDecimal(item.PersonalScore).setScale(1,
                    BigDecimal.ROUND_HALF_UP).toPlainString()
            tv_require.text = "考试要求:${item.ExamRequire}"
        }
    }
}